<?php
/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 14/11/18
 * Time: 上午10:34
 */

class ModUserChannel extends Model {

    private $table = 'user_channel';

    // 表名
    public function tableName(){
        return $this->table;
    }

    public static function model($className=__CLASS__){
        return parent::model($className);
    }

    public function getDbConnection(){
        return Yii::app()->dbAuth;
    }

    public function select($params=array()){
        $where  = ' WHERE 1 ';
        $args   = array();

        if(!empty($params['user_id'])){
            $where .= ' AND user_id=:user_id ';
            $args[':user_id'] = $params['user_id'];
        }


        $sql = "SELECT id,user_id,channel_id
                FROM {$this->table} {$where}";

        $result = $this->getDbConnection()->getAll($sql, $args);
        return $result;
    }
    
    public function addUserChannel($params){
    	$result = $this->getDbConnection()->multiInsert($params, $this->table, FALSE);
    	return $result;
    }
    

} 